package com.kiki.stater.tree;

/**
 * Created by mazeyi on 2021/2/25.
 */
public class TreeTest {
    Integer[] arr = {4,1,6,0,2,5,7,null,null,null,3,null,null,null,8};
    int i = 0;

    public TreeNode fillTree(TreeNode treeNode){
        if(treeNode == null){
            treeNode = new TreeNode(arr[i]);
            System.out.println("根:" + arr[i]);
        }

        treeNode.left = new TreeNode(arr[i+1]);
        System.out.println("根:" + arr[i] + "left:" + arr[i + 1]);

        treeNode.right = new TreeNode(arr[i + 2]);
        System.out.println("根:" + arr[i] + "left:" + arr[i + 1] + "right:" + arr[i + 2]);
        i++;
        if(i < arr.length - 2){
            fillTree(treeNode.left);
            fillTree(treeNode.right);
        }
        return treeNode;
    }
    public static void main(String[] args) {
        new TreeTest().fillTree(null);
    }
}

 class TreeNode {
      int val;
      TreeNode left;
      TreeNode right;
      TreeNode() {}
      TreeNode(int val) { this.val = val; }
      TreeNode(int val, TreeNode left, TreeNode right) {
          this.val = val;
          this.left = left;
          this.right = right;
      }


  }